<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>有一个对象数组，根据某个对象属性对数组进行排序。</title>
    <link rel="stylesheet" type="text/css" href="../../style/public.css">
</head>
<body>
    <div id="section">
        <p>有一个对象数组，根据某个对象属性对数组进行排序。</p>
    </div>
	
</body>
    <script>
        var aaa = [
            {name:10},
            {name:9},
            {name:12},
            {name:5},
            {name:25}
        ]
        var sortCount = function(propertyName){
            return function(obj1,obj2){
                var value1 = obj1[propertyName];
                var value2 = obj2[propertyName];
                if (value1 < value2) {
                    return -1;
                }else if(value1 > value2){
                    return 1;
                }else{
                    return 0;
                }
            }
        }
        aaa.sort(sortCount('name'))
        console.log(aaa);

    </script>
</html>